package C8_9_ReplaceMagicNumberWithSymbolicConstant;

import org.junit.Test;

/**
 * 以字母常量取代魔法数
 *
 * @author xufy
 * @version 1.0
 **/

public class ReplaceMagicNumberWithSymbolicConstantTest {

    /**
     * 重构前
     */
    @Test
    public void test1() {
        double v = potentialEnergy(1.11, 2);
        System.out.println("重构前，计算结果：" + v);
    }

    double potentialEnergy(double mass, double height) {
        return mass * 9.81 * height;
    }

    /**
     * 重构后
     */
    @Test
    public void test2() {
        double v = potentialEnergy(1.11, 2);
        System.out.println("重构前，计算结果：" + v);
    }

    static final double GRAVITATIONAL_CONSTANT = 9.81;

    double potentialEnergy2(double mass, double height) {
        return mass * GRAVITATIONAL_CONSTANT * height;
    }

}
